Questions
10 of 29
1What is the box model in HTML?
2Can you explain the components of the Box Model?
3What’s the difference between margin, border, padding, and content?
4How does padding affect the size of an element?
5How does margin differ from padding?
6What happens when you set negative margins?
7Does padding accept negative values? Why or why not?
8How can you visualize the box model in browser dev tools?
9What is the default box-sizing value for HTML elements?
10What does box-sizing: border-box do?
11Compare box-sizing: content-box and border-box.
12How can you make two boxes align perfectly side by side with consistent spacing?
13How do margin collapsing rules work in CSS?
14Give an example of when margin collapsing might cause layout issues.
15How can you prevent margin collapsing between parent and child elements?
16What is the difference between inline, inline-block, and block elements in terms of the box model?
17Do replaced elements (like <img>, <input>) follow the same box model rules?
18How do width and height interact with padding and border in the box model?
19Why might a layout break when switching from content-box to border-box?
20How would you fix an element that overflows its container due to box model miscalculations?
21How do you use the calc() function to compensate for padding or border widths?
22How does the box model interact with flexbox and grid layouts?
23Does the box model behave differently for absolutely positioned elements?
24How can you ensure consistent box sizing across all elements on a webpage?
25What’s the role of outline in the box model, and how is it different from border?
26How can you use the box model to achieve responsive layouts?
27How do you debug box model-related issues in a complex layout?
28Explain how min-width, max-width, and overflow affect the box model.
29How do borders affect element dimensions?
10 / 29

What does box-sizing: border-box do?

Understanding box-sizing: border-box in CSS

box-sizing: border-box changes the way the width and height of an element are calculated. With this value, the element's width and height include the content, padding, and border, so the total size remains as specified without adding extra space for padding or border.

Example of Border-Box
Benefits of Border-Box
  1. 1

    Ensures element total size matches the specified width and height.

  2. 2

    Simplifies layout calculations, especially with padding and borders.

  3. 3

    Prevents unexpected growth of elements due to padding or border.

  4. 4

    Recommended for consistent box sizing across layouts.

Difficulty: 3/10
Topics: layout, CSS box model, responsive design

Scenario Questions

0-2 years experience
  1. 1

    You have a div with width: 200px and padding: 20px. If you set box-sizing: border-box, what will be the total rendered width of the element?

  2. 2

    How would you modify a CSS rule to ensure that padding and border are included in the element's specified width without changing the HTML?

  3. 3

    If you forget to set box-sizing on a component that uses a 100% width layout, what visual issue might you see?

2-5 years experience
  1. 1

    We have a responsive card component that breaks layout when we add a 2px border. Walk me through how you would use box-sizing to fix it and why the previous layout failed.

  2. 2

    During a bug hunt, you notice that a modal's width is overflowing its container only on Chrome. The CSS uses box-sizing: content-box. Explain how changing to border-box could resolve the issue.

  3. 3

    When building a CSS utility library, you need to decide the default box-sizing for all elements. What trade‑offs would you consider, and how would you implement a global reset?

5-8 years experience
  1. 1

    Our design system currently uses content-box for most components, but we are seeing inconsistencies across browsers when components are nested. How would you approach refactoring the system to use border-box, and what edge cases would you watch for?

  2. 2

    Explain the performance implications, if any, of switching a large legacy codebase to border-box globally. How would you mitigate regression risks during the rollout?

  3. 3

    A component library ships with both box-sizing options via a CSS variable. How would you design the API to let consumers opt‑in to border-box without breaking existing layouts?

8+ years experience
  1. 1

    Our company is migrating a monolithic web app to a micro‑frontend architecture. Different teams have different box-sizing defaults, causing layout clashes. How would you establish a cross‑team strategy to standardize box-sizing while allowing incremental migration?

  2. 2

    Consider a long‑term maintenance plan for a global CSS framework that must support legacy browsers (IE11) and modern browsers. How would you decide whether to enforce border-box as the default, and what fallback mechanisms would you put in place?

  3. 3

    You need to evaluate the impact of changing the default box-sizing on SEO and page speed metrics across thousands of pages. Outline the steps and tooling you would use to assess and roll out this change safely.

Follow-up Questions

  • Can you describe how the CSS box model changes with border-box?
  • What are common pitfalls when mixing box-sizing values in a component hierarchy?
  • How would you test that your box-sizing changes didn't introduce regressions?